/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;
import com.jfinal.core.Controller;
import model.User;
import java.util.List;
/**
 *
 * @author Lx
 */

public class Usercontroller extends Controller{
     public void index(){
        List<User> users=User.dao.find("select * from user");
        setAttr("users", users);
        System.out.println("得到数据"+users.size()+"个");
        render("list.jsp");
    }
   public void form(){
      
         Integer id=getParaToInt(0);
       if(id!=null&&id>0){
           setAttr("user", User.dao.findById(id));
       }
       render("form.jsp");
   }
   public void submit(){
      User user = getModel(User.class,"user"); //前端传过来的class  名为form表中的属性名
      user.save();
       redirect("/user");//重定向
   }
   public void update(){
       User user = getModel(User.class,"user");
        user.update();
        redirect("/user");
   }
   
   public void edit(){
      form();
   }
   public void del(){
       User.dao.deleteById(getPara(0));
       redirect("/user");
   }
}
